<template>
    <view class="content">
        <view>
            <text class="title">{{title}}</text>
        </view>
        <view class="uni-list">
            <view class="uni-list-cell" v-for="(item,index) in btnTitles" :key="index">
                <button class="uni-list-cell-navigate uni-navigate-right" @click="btnclick(index)">
                    {{item}}
                </button>				
            </view>
        </view>
        <text>{{result}}</text>
    </view>
</template>
<script>
	
	const hjAlibc = uni.requireNativePlugin('dasu-alibaichuan');
	
    export default {
        data() {
            return {
                title: '阿里百川UniApp插件',
                btnTitles: [
                '百川初始化', 
                '授权并登录', 
                '用户是否已登录', 
                '退出登录',
                '跳转购物车', 
                '跳转到我的订单', 
                '跳转到优惠券',
                '打开淘宝商品',
                ],
                result: '',
            }
        },
        onLoad() {
			
        },
        methods: {		
		
        btnclick: function(e) {
                const bcPlugin = uni.requireNativePlugin('dasu-alibaichuan');
                switch (e) {
                    case 0:
                        if (plus.device.vendor == 'Apple') {
                            bcPlugin.BCSDKInitWithAppkey('30011709', result => {
                                uni.showModal({
                                    title: '百川初始化',
                                    content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                })
                            });
                        }
                        this.result = '点击了：' + this.btnTitles[e];
                        break;
                    case 1:
                        if (plus.device.vendor == 'Apple') {
                            bcPlugin.BCAuth(result => {
                                uni.showModal({
                                    title: '授权登录',
                                    content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                })
								console.log(result)
                            });
                        } else {
                            bcPlugin.login(result => {
								console.log(result)
                                if (result.type == "success") {
                                    uni.showToast({
                                        title: '授权成功'
                                    });
                                } else {
                                    //授权失败，包括用户取消登录 
                                    uni.showToast({
                                        title: '授权失败,如有异常，请联系客服。'
                                    });
									console.log(result)
                                }
                            });
                        }
                        this.result = '点击了：' + this.btnTitles[e];
                        break;
                    case 2:
                        if (plus.device.vendor == 'Apple') {
                            bcPlugin.BCIsUserLogin(result => {
                                uni.showModal({
                                    title: '用户是否登录',
                                    content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                })
                            });
                        } else {
                            bcPlugin.checkSession(reg => {
                                if (reg) {
                                    //reg 存在 获取seesion
                                        uni.showModal({
                                        title: 'session',
                                        content: 'reg:'+reg
                                    })
                                } else {
                                    //reg过期 获取session
                                    bcPlugin.getSession(result => {});
                                }
                            });
                        }
                        this.result = '点击了：' + this.btnTitles[e];
                        break;
                        case 3:
                            if (plus.device.vendor == 'Apple') {
                                bcPlugin.BCUserLogout(result => {
                                    uni.showModal({
                                        title: '退出登陆',
                                        content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                    })
                                });
                            } else {
                                bcPlugin.logout(result => {

                                      uni.showModal({
                                          title: '退出登陆',
                                          content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                      })

                                });
                            }
                            this.result = '点击了：' + this.btnTitles[e];
                            break;
                    case 4:
                        if (plus.device.vendor == 'Apple') {
                            bcPlugin.BCJumpMyCart(result => {
                               uni.showModal({
                                title:'跳转到我的购物车',
                                content:'code:'+result['code'] + '\nmessage:' + result['message']
                               });
                            });
                        } else {
                            bcPlugin.OpenMyCart(result => {

                                  uni.showModal({
                                      title: '购物车',
                                      content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                  })

                            });
                        }
                        this.result = '点击了：' + this.btnTitles[e];
                        break;      
                    case 5:
                        if (plus.device.vendor == 'Apple') {
                            bcPlugin.BCJumpMyOrder(result => {
                                uni.showModal({
                                    title:'跳转到我的订单',
                                    content:'code:'+result['code'] + '\nmessage:' + result['message']
                                });
                            });
                        } else {
                            bcPlugin.OpenMyOrders({status:0,type:true},result => {

                                uni.showToast({title:JSON.stringify(result),icon:'none'});

                                           if(result.type=="success")
                                           {
                                               //操作成功，返回内容 result.msg
                                             console.log("msg:"+result.msg);     
                                           }else{

                                              //失败
                                             console.log("code:"+result.code+" - "+"msg:"+result.msg);     
                                           }

                            });
                        }
                        this.result = '点击了：' + this.btnTitles[e];
                        break;  
                        case 6:
                        if (plus.device.vendor == 'Apple') {
                            bcPlugin.BCGetCoupons("https:\/\/uland.taobao.com/coupon/edetail?e=bv45wXFXDV0GQASttHIRqYvw81bTTFV3AoNz1oh6sSBw24URnwfVYZkqkkGn1ka4Io61VIt2QOAlLeoz%2FuwL9wBa6vm8LTMVFpTdiJGYMLzZzF%2F7iLsQj%2Bdth9k8bqqSHKTgBzHkoM7XTQC0vfau6E%2F9Zk7cDx8UPY2GSU4OeGfCMAzsjqHNZlTH5bfxlzo3&traceId=0b15337b15522805995965072e&union_lens=lensId:0b0fc0d4_0bf6_1696b223c3d_2b97&xId=TNqIni6VJhuZ9lqkONqDbz9lYtQjXIVM9Vi4arlsiXoIG879SnaSb2HjXpRzY0CIEsykszYfmZWzbvz2I68AfA",result => {
                                uni.showModal({
                                    title: '跳转优惠券',
                                    content: 'code:' + result['code'] + '\nmessage:' + result['message']
                                })
                            });
                        } else {
                            bcPlugin.url({url:"https:\/\/uland.taobao.com/coupon/edetail?e=bv45wXFXDV0GQASttHIRqYvw81bTTFV3AoNz1oh6sSBw24URnwfVYZkqkkGn1ka4Io61VIt2QOAlLeoz%2FuwL9wBa6vm8LTMVFpTdiJGYMLzZzF%2F7iLsQj%2Bdth9k8bqqSHKTgBzHkoM7XTQC0vfau6E%2F9Zk7cDx8UPY2GSU4OeGfCMAzsjqHNZlTH5bfxlzo3&traceId=0b15337b15522805995965072e&union_lens=lensId:0b0fc0d4_0bf6_1696b223c3d_2b97&xId=TNqIni6VJhuZ9lqkONqDbz9lYtQjXIVM9Vi4arlsiXoIG879SnaSb2HjXpRzY0CIEsykszYfmZWzbvz2I68AfA"},result => {

                                uni.showToast({title:JSON.stringify(result),icon:'none'});

                                           if(result.type=="success")
                                           {
                                               //操作成功，返回内容 result.msg
                                             console.log("msg:"+result.msg);     
                                           }else{

                                              //失败
                                             console.log("code:"+result.code+" - "+"msg:"+result.msg);     
                                           }

                            });
                        }
                        this.result = '点击了：' + this.btnTitles[e];
                        break;      
                }
            },
        }
    }
</script>

<style lang='scss'>
    .content {
        text-align: center;
        height: 400upx;
    }

    .logo {
        height: 200upx;
        width: 200upx;
        margin-top: 20upx;
    }

    .title {
        font-size: 36upx;
        color: #8f8f94;
    }
</style>